<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
	    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	    <link rel="stylesheet" type="text/css" href="/books/css/index.css"/>
	    <script type="text/javascript" src="/books/js/jquery.1.9.1.js" ></script>
	    <script type="text/javascript" src="/books/js/mobileSelect.js"></script>
		<link rel="stylesheet" type="text/css" href="/books/css/mobileSelect.css"/>
	    <script type="text/javascript" src="/books/js/rem.js" ></script>
	    <script type="text/javascript" src="/plan/dist/mescroll.min.js" ></script>
		<link rel="stylesheet" type="text/css" href="/plan/dist/mescroll.min.css"/>
		<script type="text/javascript" src="/books/js/jquery.slimscroll.min.js" ></script>

		<title>现金日记账</title>
	</head>
	<style>


{if $books_auth['add']}
/*列表*/
.mescroll{
	position: fixed;
	top: 46px;
	bottom: 49px;
	height: auto;
}

.mescroll-totop{
	bottom:57px;
}
{else}
/*列表*/
.mescroll{
	position: fixed;
	top: 46px;
	bottom: 0px;
	height: auto;
}
.mescroll-totop{
	bottom:30px;
}
{/if}
.mescroll-empty .empty-icon{
    display: block;
    width: 2.82rem;
    margin: 37% auto;
}
.examine{
	width: 100%!important;
	display: none;
}



</style>
	<body>
		<div class="top">
			<div class="top_left">
				<span class="top_left_con1">
					<div id="trigger4" class="trigger4" style="display: inline-block;font-size: 0.28rem;color: #555;">
						开会周次
					</div>
				</span>
				<img class="top_left_xia1" src="/books/img/jtxia.png" />
				<img class="top_left_up1" src="/books/img/jtup.png" />
			</div>
		{if $books_auth['all']}	
			<div class="top_right">
				<span class="top_left_con2">分公司</span>
				<img class="top_left_xia2" src="/books/img/jtxia.png" />
				<img class="top_left_up2" src="/books/img/jtup.png" />
			</div>
		 {/if}
		</div>
		{if $books_auth['all']}	
		<ul class="examine">
			 <li i="0">全部分公司<img src="/books/img/jtyou.png" /></li>
			{foreach name="$dept_list" item="vo" }
				<li i="{$key}" >{$vo}<img src="/books/img/jtyou.png" /></li>
			{/foreach}
		</ul>

		{/if}
		<div id="mescroll" class="mescroll">
			<ul class="list" id="dataList">
		      
		    </ul>
		</div>
		{if $books_auth['add']}
		<a href="/index/books/add"><div class="pay">新增</div></a>
		{/if}
		<input type="hidden" id="time">
		<input type="hidden" id="year">
	</body>
	<script>
		$(function(){
				$(".examine").slimScroll({ height: '100%' });
			var winHeight = $(window).height();
			var topHeight = $('.top').height();
			var topPadding = parseFloat($('.top').css('padding-top'))*2;
			var conHeight = winHeight-topHeight;
			$('.examine').css('height',conHeight+'px');
			$('.examine ul').css('min-height',conHeight+1+'px');
		
			$('.top_right').click(function(){
				$('.examine').toggle();
				$('.top_left_xia2').toggle();
				$('.top_left_up2').toggle();
				$('.top_left_xia1').show();
				$('.top_left_up1').hide();
				$('.top_left_con1').css('color','#555');
				$('.top_left_con2').css('color','#000');
			});
			$('.examine li').click(function(){
				console.log(22222);
				$('.top_left_xia2').show();
				$('.top_left_up2').hide();
				$(this).css('color','#457bc7').siblings().css('color','#000');
				$('.examine').hide();
				var CompanyName = $(this).text();
				$('.top_left_con2').text(CompanyName);
				$('.top_left_con2').css('color','#555');
			});
		});
	</script>
<script>
 //创建MeScroll对象
var mescroll = new MeScroll("mescroll", {

    up: {
        callback: getListData, //上拉加载的回调
        page: {
			num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
			size: 10 //每页数据条数,默认10
		},
        isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
		noMoreSize: 1, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
		empty: {
			icon: "/plan/img/wu.png", //图标,默认null
			tip: " ", //提示
		},
		clearEmptyId: "dataList", //相当于同时设置了clearId和empty.warpId; 简化写法;默认null; 注意vue中不能配置此项
		toTop:{ //配置回到顶部按钮
			src : "/plan/img/mescroll-totop.png", //默认滚动到1000px显示,可配置offset修改
			//offset : 1000
		},
		htmlNodata: '<p class="upwarp-nodata">-- END --</p>',
		lazyLoad: {
        	use: true // 是否开启懒加载,默认false
        }
    }
});
/*初始化菜单*/


 var department=0;
$(".examine li").click(function(){
	var i=$(this).attr("i");
	if(department!=i) {
		//更改列表条件
		department=i;
		//重置列表数据
		mescroll.resetUpScroll();
		//隐藏回到顶部按钮
		mescroll.hideTopBtn();
	}
})
var time = $("#time").val();
var year = $("#year").val();

function getListDataFromNet(pageNum,pageSize,department,time,year,successCallback,errorCallback) {
	//console.log(pageSize);
    $.ajax({
      url: '/index/books/lists_ajax?offset='+pageNum+'&limit='+pageSize+'&department='+department+'&time='+time+'&year='+year,
      type: 'get',
      success: function (res) {
      //console.log(res);
        var list = res.rows;
   		successCallback(list,res.total);
      },
       error: errorCallback
    })
  }
  	/*设置列表数据*/
	function setListData(curPageData){
		var listDom=document.getElementById("dataList");
		for (var i = 0; i < curPageData.length; i++) {
			var value=curPageData[i];

			var html ='<a href="/index/books/view/ids/'+value.id+'"><p class="number">'+value.department_text
      	+'<span class="num_right">'+value.week_text+'周 '+value.start_time+','+value.end_time
      	+'</span></p><div class="info_left"><p>收入</p><p>'+value.income_text
      	+'</p></div><div class="info_right"><p>支出</p><p>'+value.expenses_text
      	+'</p></div></a>';
			var liDom=document.createElement("li");
			liDom.innerHTML=html;
			listDom.appendChild(liDom);
		}
	}
	{if $books_auth['all']}	
	var department=0;
	{else}
	var department={$books_auth['department']};
	{/if}
	var arr = [];
	var DefaultsDate = {$DefaultsDate};
	var DefaultsDateW = {$DefaultsDateW};
	var years = {$DefaultsDate};
	var week_text = {$DefaultsDateW};
  	$.ajax({
	  url: '/api/ajax/year_week',
	  type: 'post',
	  async: false,
	  data:{type:2,year:years,week_text:week_text,department:department},
	  success: function (year) {
	  	   arr = year.data.data;
	  	   DefaultsDate = year.data.year_more;
	  	   DefaultsDateW = year.data.week_more;
	  		/*$.each(year.data,function (index,value) {
	  			 arr[index] = value;
	  			$.get('https://oa.fc62.com/api/ajax/year?year='+value.value,function (week) {
						arr[index]['childs'] = week.data;
					});

		   });*/
	  }
	});
  	var mobileSelect4 = new MobileSelect({
	    trigger: '#trigger4',
	    title: '周次选择',
	    wheels: [{data:arr}],
	    position:[DefaultsDate,DefaultsDateW],
		 transitionEnd:function(indexArr, data){
		        
		 },
		 callback:function(indexArr, data){
		 	if(data[0].value != 0){
			 	var strs = data[1].name.split(",");
			 	$('#trigger4').text(strs[0]);
			    $('#week').val(data[1].value);
			    time = data[1].value;
		    }else{
		    	time = 0;
		    }
		    year = data[0].value;
		    console.log(year);
			//重置列表数据
			mescroll.resetUpScroll();
			//隐藏回到顶部按钮
			mescroll.hideTopBtn();
		 }
	});
	


	/*联网加载列表数据  page = {num:1, size:10}; num:当前页 从1开始, size:每页数据条数 */
function getListData(page){
	var pageNum = page.num - 1;
	//联网加载数据
	getListDataFromNet(pageNum, page.size,department,time,year, function(curPageData,totalSize){
		//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
		//mescroll会根据传的参数,自动判断列表如果无任何数据,则提示空;列表无下一页数据,则提示无更多数据;
		console.log("page.num="+pageNum+", page.size="+page.size+", curPageData.length="+curPageData.length);
		//方法二(推荐): 后台接口有返回列表的总数据量 totalSize
		mescroll.endBySize(curPageData.length, totalSize); //必传参数(当前页的数据个数, 总数据量)
		//提示:curPageData.length必传的原因:
		// 1.判断是否有下一页的首要依据: 当传的值小于page.size时,则一定会认为无更多数据.
		// 2.比传入的totalPage, totalSize, hasNext具有更高的判断优先级
		// 3.使配置的noMoreSize生效
		//设置列表数据
		setListData(curPageData);
	}, function(){
		//联网失败的回调,隐藏下拉刷新和上拉加载的状态;
        mescroll.endErr();
	});
}
</script>


</html>
